package ControlLayer;

import java.util.ArrayList;
import DBLayer.DBFilm;
import DBLayer.DBForestilling;
import DBLayer.DBSal;
import DBLayer.DbConnection1;
import ModelLayer.*;

public class ForestillingsCtr 
{
	
	public ForestillingsCtr()
	{
	}
	/**
	 * Creates a new forestilling with
	 * @param id
	 * @param dato
	 * @param start
	 * @param slut
	 * @param film
	 * @param sal
	 */
	public void createForestilling(int id, String dato, String start, String slut, Film film, Sal sal) 
	{
		Forestilling fsObj = new Forestilling();

		fsObj.setForestillingId(id);
		fsObj.setFremvisningsDato(dato);
		fsObj.setStart(start);
		fsObj.setSlut(slut);
		fsObj.setFilm(film);
		fsObj.setSal(sal);

		try 
		{
			DbConnection1.startTransaction();
			DBForestilling dbfs = new DBForestilling();
			dbfs.insertForestilling(fsObj);
			DbConnection1.commitTransaction();
		} 
		catch (Exception e) 
		{
			DbConnection1.rollbackTransaction();
		}
	}
	/**
	 * Creates a new Film with
	 * @param titel
	 * @param beskrivelse
	 * @param laengde
	 * @param is3D
	 * @param genre
	 * @param billetPris
	 */
	public void createFilm(String titel, String beskrivelse, String laengde, boolean is3D, 
    		String genre, double billetPris) 
	{
		Film filmObj = new Film();

		filmObj.setTitel(titel);
		filmObj.setBeskrivelse(beskrivelse);
		filmObj.setLaengde(laengde);
		filmObj.setIs3D(is3D);
		filmObj.setGenre(genre);
		filmObj.setBilletPris(billetPris);

		try 
		{
			DbConnection1.startTransaction();
			DBFilm dbfilm = new DBFilm();
			dbfilm.insertFilm(filmObj);
			DbConnection1.commitTransaction();
		} 
		catch (Exception e) 
		{
			DbConnection1.rollbackTransaction();
		}
	}
	/**
	 * Finds a Forestilling with
	 * @param id
	 * @return
	 */
	public Forestilling findForestilling(int id) 
	{
		DBForestilling dbForestilling = new DBForestilling();
		Forestilling result = dbForestilling.getForestilling(id, true);
		return result;
	}
	/**
	 * Finds a Film with
	 * @param titel
	 * @return
	 */
	public Film findFilm(String titel) 
	{
		DBFilm dbFilm = new DBFilm();
		Film result = dbFilm.getFilm(titel, false);
		return result;
	}
	/**
	 * Removes a Forestilling with
	 * @param id
	 */
	public void removeForestilling(int id) 
	{
		DBForestilling dbForestilling = new DBForestilling();
		dbForestilling.deleteForestilling(id);
	}
	/**
	 * Finds all Forestillinger with no parameter
	 * @return
	 */
	public ArrayList<Forestilling> getAllForestilling()
	{
		DBForestilling dbForestilling = new DBForestilling();
		ArrayList<Forestilling> result = dbForestilling.getAllForestillinger(true);
		return result;
	}
	/**
	 * Updates a Forestilling with
	 * @param f
	 */
	public void updateForestilling(Forestilling f)
	{
		DBForestilling dbForestilling = new DBForestilling();
		dbForestilling.updateForestilling(f);
	}
	/**
	 * Finds all Films with no parameter
	 * @return
	 */
	public ArrayList<Film> getAllFilm()
	{
		DBFilm dbFilm = new DBFilm();
		ArrayList<Film> result = dbFilm.getAllFilm(true);
		return result;
	}
	/**
	 * Finds a Sal with
	 * @param id
	 * @return
	 */
	public Sal getSal(byte id)
	{
		Sal sal = new Sal();
		DBSal dbSal = new DBSal();
		sal = dbSal.getSal(id, true);
		return sal;	
	}
}

